/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       new_game_details.cpp

	$Header: /game/new_game_details.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "new_game_details.h"

#include "adaptor_handler.h"
#include "bitmap_layer_window.h"
#include "bitmap_group_cache.h"
#include "bound_handler.h"
#include "button_cache.h"
#include "external_string.h"
#include "interface_help.h"
#include "text_window.h"
#include "standard_fonts.h"
#include "toggle_button.h"

extern t_bitmap_group_cache const k_new_map_bitmaps;
static t_bitmap_group_cache    g_details_bitmaps( "new_game_details" );
static t_external_string const k_text_title( "details_title" );
t_external_string const        k_text_size( "size" );
t_external_string const        k_text_difficulty( "difficulty" );
t_external_string const        k_text_players( "players" );
static t_external_string const k_text_human_players( "human_players" );
t_external_string const        k_text_allies( "allies" );
t_external_string const        k_text_victory_conditions( "victory_conditions" );
t_external_string const        k_text_loss_conditions( "loss_conditions" );
static t_external_string const k_text_number_of_maps( "number_of_maps.misc" );
extern t_external_string const k_text_cancel;
extern t_external_string const k_text_ok;


extern t_button_cache g_large_button;
extern t_button_cache g_checkbox;

// ---------------------------------------------------------------------
// new game details dialog.  Choose which columns you wish displayed.
// ---------------------------------------------------------------------
t_new_game_details_dialog::t_new_game_details_dialog( bool size,   bool difficulty, bool players, 
		                                              bool humans, bool allies, bool number_of_maps,
													  t_window* parent )
			             : t_dialog_box( parent )
{
	t_bitmap_group_ptr bitmaps = g_details_bitmaps.get();

	m_new_game_bitmaps = k_new_map_bitmaps.get();

	t_screen_rect window_size = bitmaps->find( "window_size" )->get_rect();
	t_screen_rect rect;

	m_size_checked			= size;
	m_difficulty_checked	= difficulty;
	m_players_checked		= players;
	m_humans_checked		= humans;
	m_allies_checked		= allies;
	m_number_of_maps_checked = number_of_maps;
	//m_map_checked;

	// add "Show:" title
	t_text_window* text_window;

	rect = bitmaps->find( "title_text" )->get_rect();
	text_window = new t_text_window( get_font( rect.height() ), rect, this,
		                             k_text_title, t_pixel_24(0,0,0));
	text_window->set_drop_shadow( true, t_pixel_24(200,200,200) );

	add_item( "size", &m_size_checked, k_text_size, bitmaps );
	add_item( "difficulty", &m_difficulty_checked, k_text_difficulty, bitmaps );
	add_item( "players", &m_players_checked, k_text_players, bitmaps );
	add_item( "humans", &m_humans_checked, k_text_human_players, bitmaps );
	add_item( "allies", &m_allies_checked, k_text_allies, bitmaps );
	add_item( "maps", &m_number_of_maps_checked, k_text_number_of_maps, bitmaps );
	//add_item( "win", &m_victory_checked, k_text_victory_conditions, bitmaps );
	//add_item( "lose", &m_loss_checked, k_text_loss_conditions, bitmaps );

	// add "OK" button
	t_help_block const&   help = get_help_block( "map_details" );
	t_button* button;

	rect = bitmaps->find( "ok" )->get_rect();
	button = new t_button( g_large_button.get(), rect.top_left(), this, k_text_ok );
	add_close_button( button, 1 );
	set_help( button, help, "ok" );

	// add "cancel" button
	rect = bitmaps->find( "cancel" )->get_rect();
	button = new t_button( g_large_button.get(), rect.top_left(), this, k_text_cancel );
	add_close_button( button, 0 );
	set_help( button, help, "cancel" );

	window_size += t_screen_point( (get_parent()->get_width() - window_size.width()) / 2, 
		                           (get_parent()->get_height() - window_size.height()) / 2 );
	init( window_size );
}

// ---------------------------------------------------------------------
// new game details dialog.  Choose which columns you wish displayed.
// ---------------------------------------------------------------------
void t_new_game_details_dialog::add_item( std::string const& name, bool* variable,
										  std::string const& text, t_bitmap_group* bitmaps )
{
	t_toggle_button*       checkbox;
	t_bitmap_layer const*  icon;
	t_bitmap_layer_window* icon_window;
	t_screen_rect          rect;
	t_text_window*         text_window;
	t_help_block const&    help = get_help_block( "map_details" );

	rect = bitmaps->find( (name + "_icon").c_str() )->get_rect();
	icon = m_new_game_bitmaps->find( (name + "_released").c_str() );
	icon_window = new t_bitmap_layer_window( icon, rect.top_left() - icon->get_rect().top_left(),
		                                     this );
	set_help( icon_window, help, name );

	rect = bitmaps->find( (name + "_checkbox" ).c_str() )->get_rect();
	checkbox = new t_toggle_button( g_checkbox.get(), rect.top_left(), this );
	checkbox->set_pressed( *variable );
	checkbox->set_click_handler( add_2nd_argument( 
		                         bound_handler( *this, &t_new_game_details_dialog::button_clicked ),
								 variable ) );

	rect = bitmaps->find( (name + "_text").c_str() )->get_rect();
	text_window = new t_text_window( get_font( rect.height() ), rect, this, text,
		                             t_pixel_24(0,0,0) );
	text_window->set_drop_shadow( true, t_pixel_24(200,200,200) );
}

// ---------------------------------------------------------------------
// new game details dialog.  Choose which columns you wish displayed.
// ---------------------------------------------------------------------
void t_new_game_details_dialog::button_clicked( t_button* button, bool* variable )
{
	*variable = button->is_pressed();
}
